// pages/personal/personal.js
const app = getApp()
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fId:'',
    name:'',
    item:'',
    list:[],
    num:null,
    url:'',
    pageNumber:1,
    totalPages:1,
  },
  getList(){
    var that = this
    app.req({
      url:'blessmini/rank/rankDetail',
      data:{
        pageSize:10,
        pageNumber:that.data.pageNumber,
        friendId:that.data.fId
      },
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          var rows = res.data.list.rows
          for(var i in rows){
            rows[i].createTime = utils.itemDateToShow(rows[i].createTime,1,true,false).substring(5)
          }
          that.setData({
            item: res.data,
            list: that.data.list.concat(rows),
            totalPages: res.data.list.totalPages
          })
          console.log('人情账', that.data.list)
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      fId: options.id,
      name: options.name,
      num:options.num,
      url:options.url
    })
    wx.setNavigationBarTitle({
      title: "我和"+that.data.name+"的人情账"
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      list:[],
      pageNumber:1,
    })
    that.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if (that.data.totalPages>that.data.pageNumber){
      that.setData({
        pageNumber:that.data.pageNumber+1
      })
      that.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})